package com.example.clientsideapplication;

import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class OfferListAdapter extends ArrayAdapter {
	private int resource;
	private LayoutInflater inflater;

	public OfferListAdapter(Context ctx, int resourceId, List objects) {
		super(ctx, resourceId, objects);
		resource = resourceId;
		inflater = LayoutInflater.from(ctx);
		
		int duration = Toast.LENGTH_LONG;
		Toast toast = Toast
					.makeText(
							ctx,
							"Tenere premuto sul prodotto per visualizzare il menu delle operazioni.",
							duration);
		toast.show();
	}

	public View getView(int position, View convertView, ViewGroup parent) {

		convertView = (RelativeLayout) inflater.inflate(resource, null);

		Offer offer = (Offer) getItem(position);

		TextView productName = (TextView) convertView.findViewById(R.id.offer_list_product_name_tw);
		productName.setText(offer.getProductName());

		TextView productCategory = (TextView) convertView
				.findViewById(R.id.offer_list_product_category_tw);
		productCategory.setText(offer.getProductCategory().toString());

		TextView productPrice = (TextView) convertView
				.findViewById(R.id.offer_list_product_price_tw);
		productPrice.setText(Double.toString(offer.getProductPrice()) + " euro");

		return convertView;
	}

}
